<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/orders' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-input
        placeholder="请输入内容"
        class="input-with-select"
        style="width: 500px"
      >
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>

      <!-- orderlist -->
      <el-table :data="orderlist" style="width: 100%" border>
        <el-table-column type="index" label="顺序"></el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === 1"
              >已付</el-tag
            >
            <el-tag type="danger" v-else>未付</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template>
            <el-button
              type="primary"
              size="small"
              icon="el-icon-edit"
              circle
              @click="showEditDialogVisible"
            ></el-button>
            <el-button
              type="success"
              size="small"
              icon="el-icon-location"
              circle
              @click="showProDialogVisible"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 15, 20, 25]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 编辑试图 -->
    <el-dialog
      title="修改信息"
      :visible.sync="EditDialogVisible"
      width="30%"
      @close="EditDialogClosed"
    >
      <!-- 检验信息 -->
      <el-form
        :model="addForm"
        :rules="addFormRules"
        ref="addFormRef"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="请选择地址" prop="address1">
          <!-- 级联 导入的是 citydata address1要为数组形式-->
          <el-cascader
            expand-trigger="hover"
            :options="citydata"
            v-model="addForm.address1"
            @change="handleChange"
            style="width: 100%"
          >
          </el-cascader>
        </el-form-item>

        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="EditDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="EditDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 当前进度视图 -->
    <el-dialog title="物流进度" :visible.sync="proDialogVisible" width="30%">
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="proDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="proDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import citydata from "./citydata.js";

export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      //总信息条数
      total: 0,
      // orderlist列表
      orderlist: [],

      addForm: {
        address1: [], //级联要为数组形式
        address2: "",
      },
      //级联那里导入城市
      citydata,
      addFormRules: {
        address1: [{ required: true, trigger: "blur" }],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      EditDialogVisible: false,
      proDialogVisible: false,

      progressInfo: [], //进度消息
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: {
          pagenum: this.queryInfo.pagenum,
          pagesize: this.queryInfo.pagesize,
        },
      });
      if (res.meta.status !== 200) {
        this.$message.error("获取信息失败！");
      }
      this.orderlist = res.data.goods;
      this.total = res.data.total;
      console.log(this.orderlist);
    },
    // 级联改变
    handleChange() {},
    //编辑试图
    showEditDialogVisible() {
      this.EditDialogVisible = true;
    },
    //关闭编辑试图
    EditDialogClosed() {
      this.$refs.addFormRef.resetFields();
    },
    //改变显示条数
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    //当前页码
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum;
      this.getOrderList();
    },

    // 进度视图
    async showProDialogVisible() {
      // const { data: res } = await this.$http.get("/kuaidi/804909574412544580");

      // if (res.meta.status !== 200) {
      //   return this.$message.error("获取物流进度失败！");
      // }
      // this.progressInfo = res.data;
      // console.log(this.progressInfo);
      //提供的信息有误啊 打不开的
      this.proDialogVisible = true;
    },
  },
};
</script>
<style lang="less" scoped>
.el-table {
  margin-top: 20px;
}
</style>